<?php

namespace Model\UserBundle\Controller;

use Model\UserBundle\Entity\User;
use Model\UserGroupsBundle\Model\UserGroupsModel;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

use Symfony\Component\HttpFoundation\Request;
use Base\BaseController;
use Model\UserBundle\Entity\User as Entity;
use Model\UserBundle\Setting\UserSetting;

/**
 * @route("/admin/")
 */
class UserAdminController extends BaseController
{

    /**
     * @route("User/add",name="UserPreAdd")
     */
    public function add()
    {
        die("NOT ALLOWED !");
        //通用代码
        $this->setSetting(new UserSetting($this->getDoctrine()));
        return $this->comAdd();
    }

    /**
     * @route("User/add/do",name="UserDoAdd")
     *
     * @Method({"GET", "POST"})
     */
    public function doAdd(Request $request)
    {
        die("NOT ALLOWED !");
        //私有代码
        $user = New User();
        $user->setAddTime(time());
        //通用代码
        $this->setSetting(new UserSetting($this->getDoctrine()));
        return $this->comDoAdd($request,$user);
    }

    /**
     * @route("User/edit/{id}",name="UserPreEdit")
     */
    public function edit(Entity $entity)
    {
        $this->setSetting(new UserSetting($this->getDoctrine()));
        return $this->comEdit($entity);
    }

    /**
     * @route("User/edit/{id}/do",name="UserDoEdit")
     *
     * @Method({"GET", "POST"})
     */
    public function doEdit(Request $request,Entity $entity)
    {
        $this->setSetting(new UserSetting($this->getDoctrine()));
        return $this->comDoEdit($request,$entity);
    }

    /**
     * @route("User",name="UserLists")
     */
    public function lists()
    {
        //私有部分
        $SAMPLECategoryModel = new UserGroupsModel($this->getDoctrine());
        $classes = $SAMPLECategoryModel->getAllUserGroupsTree();
//        $classes = array();
        $tools = array("UserGroups"    => $classes,);

        //通用部分
        $this->setSetting(new UserSetting($this->getDoctrine()->getManager()));
        return $this->comLists($tools);
    }


    /**
     * @route("User/tools",name="UserTools")
     */
    public function tools(Request $request)
    {
        $this->setSetting(new UserSetting($this->getDoctrine()));
        return $this->comTools($request);
    }

}
